package com.he.springcloud.controller;

import com.he.springcloud.service.HystrixPaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname: HystrixController
 * @Description: Hystrix控制层
 * @Date: 2021/9/8
 * @Author: huwei
 */
@RestController
@RequestMapping("/hystrix/payment")
@Slf4j
public class HystrixController {

    @Autowired
    private HystrixPaymentService hystrixPaymentService;

    @Value("${server.port}")
    private String port;

    /**
     * 模拟成功的方法
     */
    @GetMapping("/success/{id}")
    public String getDataInfoSuccess(@PathVariable("id")Integer id){
        return hystrixPaymentService.getDataIndoSuccess(id);
    }

    /**
     * 模拟服务降级的方法
     */
    @GetMapping("/error/{id}")
    public String getDataInfoError(@PathVariable("id")Integer id){
        return hystrixPaymentService.getDataInfoError(id);
    }

    /**
     * 模拟服务熔断方法
     */
    @GetMapping("/fuse/{id}")
    public String getDataInfoErrorFuse(@PathVariable("id")Integer id){
        return hystrixPaymentService.getDataErrorForErrorFuse(id);
    }
}
